<template>
  <div class="competition">
    <div class="page-header">
      <div class="header-content">
        <div class="title-section">
          <h1 class="page-title">比赛管理</h1>
          <p class="page-subtitle">管理比赛信息、赛程安排和结果记录</p>
        </div>
        <el-button type="primary" size="large" class="add-btn">
          <el-icon><Plus /></el-icon>
          添加比赛
        </el-button>
      </div>
    </div>

    <div class="content-card">
      <div class="stats-bar">
        <div class="stat-item">
          <div class="stat-number">12</div>
          <div class="stat-label">总比赛数</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">8</div>
          <div class="stat-label">已完成</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">4</div>
          <div class="stat-label">进行中</div>
        </div>
      </div>

      <el-table 
        :data="competitions" 
        style="width: 100%" 
        class="competition-table"
        :header-cell-style="{ background: '#fafafa', color: '#606266' }"
        border
      >
        <el-table-column prop="name" label="比赛名称" width="200">
          <template #default="{ row }">
            <span class="competition-name">{{ row.name }}</span>
          </template>
        </el-table-column>
        
        <el-table-column label="状态" width="120" align="center">
          <template #default="{ row }">
            <el-tag 
              :type="getStatusTagType(row.status)" 
              size="default"
            >
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        
        <el-table-column prop="date" label="比赛日期" width="150">
          <template #default="{ row }">
            <span class="date-text">{{ row.date }}</span>
          </template>
        </el-table-column>
        
        <el-table-column prop="teams" label="参赛队伍" width="250">
          <template #default="{ row }">
            <span class="teams-text">{{ row.teams.join(' vs ') }}</span>
          </template>
        </el-table-column>
        
        <el-table-column prop="result" label="比赛结果" width="150">
          <template #default="{ row }">
            <span class="result-text">{{ row.result || '待定' }}</span>
          </template>
        </el-table-column>
        
        <el-table-column label="操作" width="200" align="center">
          <template #default="{ row }">
            <div class="action-buttons">
              <el-button 
                size="small" 
                type="primary" 
                @click="editCompetition(row)"
                class="action-btn"
              >
                <el-icon><Edit /></el-icon>
                编辑
              </el-button>
              <el-button 
                size="small" 
                type="danger" 
                @click="deleteCompetition(row.id)"
                class="action-btn"
              >
                <el-icon><Delete /></el-icon>
                删除
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div v-if="competitions.length === 0" class="empty-state">
        <el-empty description="暂无比赛数据">
          <el-button type="primary">添加第一场比赛</el-button>
        </el-empty>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { Plus, Edit, Delete } from '@element-plus/icons-vue'

interface Competition {
  id: string
  name: string
  status: '未开始' | '进行中' | '已结束'
  date: string
  teams: string[]
  result?: string
}

const competitions = ref<Competition[]>([
  {
    id: '1',
    name: 'Dota2 春季赛',
    status: '已结束',
    date: '2024-03-15',
    teams: ['战队A', '战队B'],
    result: '2:1'
  },
  {
    id: '2',
    name: 'Dota2 夏季赛',
    status: '进行中',
    date: '2024-06-20',
    teams: ['战队C', '战队D'],
    result: undefined
  },
  {
    id: '3',
    name: 'Dota2 总决赛',
    status: '未开始',
    date: '2024-12-25',
    teams: ['TBD', 'TBD'],
    result: undefined
  }
])

const getStatusTagType = (status: string) => {
  const statusTypes: Record<string, 'info' | 'warning' | 'success' | 'danger'> = {
    '未开始': 'info',
    '进行中': 'warning',
    '已结束': 'success'
  }
  return statusTypes[status] || 'info'
}

const editCompetition = (competition: Competition) => {
  console.log('编辑比赛:', competition)
}

const deleteCompetition = (id: string) => {
  console.log('删除比赛:', id)
}
</script>

<style scoped>
.competition {
  padding: 0;
}

.page-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 32px 24px;
  margin-bottom: 24px;
  border-radius: 8px;
  margin: 0 24px 24px 24px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title-section h1 {
  color: white;
  margin: 0 0 8px 0;
  font-size: 28px;
  font-weight: 600;
}

.title-section p {
  color: rgba(255, 255, 255, 0.8);
  margin: 0;
  font-size: 16px;
}

.add-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-weight: 500;
}

.add-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.4);
}

.content-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin: 0 24px;
  overflow: hidden;
}

.stats-bar {
  display: flex;
  padding: 24px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 16px;
  background: white;
  border-radius: 8px;
  margin: 0 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.stat-item:first-child {
  margin-left: 0;
}

.stat-item:last-child {
  margin-right: 0;
}

.stat-number {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.competition-table {
  margin: 0;
  width: 100% !important;
}

.competition-name {
  font-weight: 500;
  color: #303133;
}

.date-text, .teams-text, .result-text {
  color: #606266;
  font-size: 14px;
}

.action-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
}

.empty-state {
  padding: 60px 24px;
  text-align: center;
}
</style>
